import { pinia, useMenusStore } from '@/stores'
import { useGet, usePost, usePut } from '@hooks/useHttp'
import { registerRouter } from '@/core/router'
import { MenusData } from '#types/menus'
import { formData } from '#types/login'
const menusStore = useMenusStore(pinia)

export default {
  async login (data: object) {
    const result = await usePost({
      url: '/login',
      data
    })
    return result
  },
  async getRandomNickName () {
    const result = await useGet({
      url: '/getNickName'
    })
    return result
  },
  async signUp (data : formData) :Promise<unknown> {
    const result = await usePut({
      url: '/signup',
      data
    })
    return result
  },
  async getMenus () {
    const result = await usePost({
      url: '/getMenus'
    })
    registerRouter(result as Array<MenusData>)
    menusStore.updateMenus(<object[]>result)
    return result
  }
}